package io.renren.modules.sys.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.DormDetailDao;
import io.renren.modules.sys.entity.DormDetailEntity;
import io.renren.modules.sys.service.DormDetailService;


@Service("dormDetailService")
public class DormDetailServiceImpl extends ServiceImpl<DormDetailDao, DormDetailEntity> implements DormDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<DormDetailEntity> wrapper = new QueryWrapper<>();
        if (params.get("area")!=null && ! params.get("area").equals("")){
            wrapper.eq("district", params.get("area"));
        }
        if (params.get("dormId")!=null && ! params.get("dormId").equals("")){
            wrapper.eq("dorm_id", params.get("dormId"));
        }
        IPage<DormDetailEntity> page = this.page(
                new Query<DormDetailEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

    @Override
    public List<Integer> getDormIdlist() {
        List<DormDetailEntity> list = this.list();
        List<Integer> collect = list.stream().map((item) -> {
            Integer dormId = item.getDormId();
            return dormId;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public List<String> getAreaIds() {
        List<DormDetailEntity> list = this.list();
        List<String> collect = list.stream().map((item) -> {
            String district = item.getDistrict();
            return district;
        }).collect(Collectors.toList());
        return collect;
    }

}